<template>
  <a-tabs>
    <a-tab-pane tab="采集模板" key="1">
      <pick-template-svr-edit :setDisabled="true"></pick-template-svr-edit>
    </a-tab-pane>
    <a-tab-pane tab="告警上报地址" key="2">
      <a-form-model :label-col="{ span: 2 }" :wrapperCol="{ span: 12 }">
        <a-form-model-item label="服务器IP地址">
          <a-input v-model="IP" style="width: 40%"></a-input>
        </a-form-model-item>
        <a-form-model-item label="端口">
          <a-input-number v-model="Port" style="width: 40%"></a-input-number>
        </a-form-model-item>
        <a-form-model-item>
          <a-space style="margin-left:280px">
            <a-button @click="setAll">下发所有节点</a-button>
          </a-space>
        </a-form-model-item>
      </a-form-model>
    </a-tab-pane>
    <a-tab-pane tab="系统维护" key="3">
      <a-button @click="forceAlarmSync">强制告警同步</a-button>
      <div style="margin-top:30px">
      <a-upload
        name="file"
        ref="uploadCtrl"
        action="api/upload/"
        :showUploadList="false"
        :multiple="false"
         @change="handlefile"
      >
        <a-button> <a-icon type="upload" />上传文件</a-button>
        <span style="margin-left:10px">文件名:{{ curFileName }}</span>
      </a-upload>
      </div>
     
    </a-tab-pane>
  </a-tabs>
</template>
<script>
import PickTemplateSvrEdit from "@/pages/realTime/PickTemplateSvrEdit.vue";
import { ctrlService } from "@/services/ctrl.js";
import {
  getMObj,
  modifyMObj,
  //removeMObj,
  //orceTemplate,
  //getTemplate,
} from "@/services/mobj.js";
import { syncAllAlarm } from "@/services/alarmAPI";
export default {
  components: {
    PickTemplateSvrEdit,
  },
  data() {
    return {
      IP: "192.168.0.1",
      Port: 57125,
      spinning:false,
      curFileName:'等待上传...',
    };
  },
  methods: {
    refresh() {
      getMObj("sm_trap").then((res) => {
        console.log(res);
      });
    },
    forceAlarmSync() {
      syncAllAlarm();
    },
    setAll() {
      let params = {};
      params["ToAll"] = "ALL";
      params["trap port"] = "" + this.Port;
      params["trap ip"] = this.IP;
      params["onlyTrap"] = "true";
      let mobj = {
        s_name: "sm_trap",
        body: {
          ip: this.IP,
          port: this.Port,
        },
      };
      modifyMObj(mobj);
      ctrlService("ALL", "SetConf", params, "box")
        .then(() => {
          alert("成功");
        })
        .catch(() => {
          alert("设置失败");
        });
    },
    handlefile(info){
      if (info.file.status === "done") {
        this.spinning = false;
        this.$message.success("版本上传成功");
        if (
          info.file.response &&
          info.file.response.result &&
          info.file.response.result.length == 1
        )
          this.curFileName = info.file.response.result[0];
        this.isUploaded = true;
        //this.fileList = []
      } else if (info.file.status === "error") {
        this.$message.error(`版本上传失败`);
        this.isUploaded = false;
        this.spinning = false;
      } else {
        this.isUploaded = false;
        this.spinning = true;
      }
      console.log("*************", info);
    },
  },
};
</script>